// mathutils.h 的实现文件

#include "mathutils.h"

#include <stdlib.h>

#include "systemutils.h"

UnsignedInt randomInt() {
    return rand();
}

UnsignedInt randomIntWithMax(UnsignedInt max) {
    return rand() % max;
}

Int randomIntIn(Int min, Int max) {
    if (min > max) 
        swapInt(&min, &max);
    return (rand() % (max - min)) + min;
}

Double random() {
    return rand() / (RAND_MAX + 1.0);
}

void swapInt(Int *a, Int *b) {
    Int c = *a;
    *a = *b;
    *b = c;
}

void seedRandomWithTime() {
    srand((UnsignedInt) currentTimeMillis());
}